package com.ffwang.springmvc.heandles;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RequestMapping("/springmvc")
@Controller
public class SpringMVCTest {

	private static final String SUCCEED = "succeed";
	/**
	 * @RequestMapping修饰类就等于类的路径+方法的路径
	 *  springmvc/testRequestMapping
	 * */
	@RequestMapping("/testRequestMapping")
	public String testRequestMapping() {
		System.out.println("testRequestMapping");
		return SUCCEED;
	}
	
	/**
	 * 指定method属性来指定请求方式
	 * @return
	 */
	@RequestMapping(value="/testMethod",method=RequestMethod.POST)
	public String testMethod(){
		System.out.println("testMethod");
		return SUCCEED;
	}
	
	
	/**
	 * 可以使用parms和headers来更加精确的映射请求。parms和headers支持简单的表达式
	 * @return
	 */
	@RequestMapping(value="/testParmsAndHeaders",params={"username","age"})
	public String testParmsAndHeaders(){
		System.out.println("testParmsAndHeaders");
		return SUCCEED;
	}
	
	/**
	 * @PathVariable可以映射URL中的占位符到目标方法的参数中
	 * @return
	 */
	@RequestMapping("/testPathVariable/{id}")
	public String testPathVariable(@PathVariable("id") Integer id){
		System.out.println("testPathVariable"+id);
		return SUCCEED;
	}
}
